package com.Dao;

import com.bean.Article;
import com.bean.Sensitive;
import com.tools.DButil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

public class SensitiveDao {

    public Set getAllSensitive() throws SQLException {
        String sql="select `sensitive` from sensitiveWord";
        QueryRunner runner=new QueryRunner(DButil.getDataSource());
        List<Sensitive> list=runner.query(sql,new BeanListHandler<Sensitive>(Sensitive.class));
        Set<String> set = null;
        for(Sensitive i:list){
            set.add(i.getSensitive());
        }
        return set;
    }

    public void addSensitive(String sensitive) throws SQLException {
        String sql="insert into sensitiveWord(`sensitive`) values (?)";
        QueryRunner runner=new QueryRunner(DButil.getDataSource());
        runner.update(sql,sensitive);
    }

    public void deleteSensitive(int id) throws SQLException {
        String sql="delete from sensitiveWord where id=?";
        QueryRunner runner=new QueryRunner(DButil.getDataSource());
        runner.update(sql,id);
    }


}
